From: Giovanni Campagna Date: Tue, 21 Dec 2010 15:26:26 +0000 (+0100) Subject: BluetoothStatus: update only devices that actually changed X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~9349 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=5f212b1ae2dd2685ccb55294da9bb929db211f39;p=gnome-shell.git BluetoothStatus: update only devices that actually changed When receiving a "devices-changed" signal from BluetoothApplet, check if some device item corresponds to an existing one, destroy the remaining and add the new ones. With this patch, signal emission when no device actually changed (which happen due to bluetoothd creating temporary devices) result in a no-op. https://bugzilla.gnome.org/show_bug.cgi?id=637690 --- diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index f2cfa8fba..47a7ed288 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -68,6 +68,7 @@ Indicator.prototype = { this._fullMenuItems = [new PopupMenu.PopupSeparatorMenuItem(), new PopupMenu.PopupMenuItem(_("Send Files to Device...")), new PopupMenu.PopupMenuItem(_("Setup a New Device..."))]; + this._hasDevices = false; this._deviceSep = this._fullMenuItems[0]; // hidden if no device exists this._fullMenuItems[1].connect('activate', function() { @@ -118,22 +119,56 @@ Indicator.prototype = { } }, - _updateDevices: function() { - this._destroyAll(this._deviceItems); - this._deviceItems = []; + _deviceCompare: function(d1, d2) { + return d1.device_path == d2.device_path && + d1.bdaddr == d2.bdaddr && + d1.can_connect == d2.can_connect && + d1.capabilities == d2.capabilities; + }, + _updateDevices: function() { let devices = this._applet.get_devices(); - let anydevice = false; + + for (let i = 0; i < this._deviceItems.length; i++) { + let item = this._deviceItems.length; + let destroy = true; + for (let j = 0; j < devices.length; j++) { + // we need to deep compare because BluetoothSimpleDevice is a boxed type + // (but we take advantage of that, because _skip will disappear the next + // time get_devices() is called) + if (this._deviceCompare(item._device, devices[i])) { + item.label.text = devices[i].alias; + devices[i]._skip = true; + destroy = false; + } + } + if (destroy) { + item.destroy(); + item._destroyed = true; + } + } + + let newlist = [ ]; + for (let i = 0; i < this._deviceItems.length; i++) { + let item = this._deviceItems[i]; + if (!item._destroyed) + newlist.push(item); + } + this._deviceItems = newlist; + + this._hasDevices = newlist.length > 0; for (let i = 0; i < devices.length; i++) { let d = devices[i]; + if (d._skip) + continue; let item = this._createDeviceItem(d); if (item) { this.menu.addMenuItem(item, this._deviceItemPosition + this._deviceItems.length); this._deviceItems.push(item); - anydevice = true; + this._hasDevices = true; } } - if (anydevice) + if (this._hasDevices) this._deviceSep.actor.show(); else this._deviceSep.actor.hide();